<?php


class lib_public extends connector {

	function lib_public() {
		$this->softbase(true);
		parent::start_template();
		$this->ectemplates->caching = false;
		$this->ectemplates->libfile = true;
	}

	public function call_menu($para, $filename='left_botton') {

		$type = empty($para[0]) ? 1 : $para[0];
		$archive = $this->fun->accept('archive', 'G');
		$action = $this->fun->accept('action', 'G');
		$loadfun = $this->fun->accept('loadfun', 'G');
		$db_table = db_prefix . 'menulink';
		$sql = "SELECT mlid,topmlid,isshortkey,menuname,linkurl,iswindow,istarget,istab,type FROM $db_table WHERE type=$type and topmlid=0 and isshow=1 ORDER BY pid DESC,mlid ASC";
		$menu = $this->dbcache->checkcache('menu_' . $type, false);
		if (!$menu) {
			$rs = $this->db->query($sql);

			$i = 1;
			while ($rsList = $this->db->fetch_assoc($rs)) {
				$topmlid = $rsList['mlid'];
				if ($i == 1) {
					$rsList['collapsed'] = 'true';
				}
				$menulink = array();

				$sqlnext = "SELECT mlid,topmlid,isshortkey,menuname,linkurl,taburl,iswindow,istarget,istab,type,width,height,archive,action,loadfun FROM $db_table WHERE topmlid=$topmlid and isshow=1 ORDER BY pid DESC,mlid ASC";
				$rsNext = $this->db->query($sqlnext);
				while ($rsNList = $this->db->fetch_assoc($rsNext)) {
					$menulink[] = $rsNList;
				}
				if ($topmlid == '57') {
					$modelarray = array();
					$modellist = $this->get_model();
					if (is_array($modellist['list']) && count($modellist['list'] > 0)) {
						foreach ($modellist['list'] as $key => $value) {
							$modelarray[$key]['mlid'] = $value['mid'];
							$modelarray[$key]['topmlid'] = $topmlid;
							$modelarray[$key]['isshortkey'] = 0;
							$modelarray[$key]['menuname'] = $value['modelname'];
							$modelarray[$key]['linkurl'] = 'index.php?archive=management&action=tab&menuid=32&loadfun=modelarticlelist&mid=' . $value['mid'];
							$modelarray[$key]['taburl'] = 'index.php?archive=management&action=tab&menuid=32&mid=' . $value['mid'];
							$modelarray[$key]['iswindow'] = 0;
							$modelarray[$key]['istarget'] = 1;
							$modelarray[$key]['istab'] = 1;
							$modelarray[$key]['type'] = 32;
							$modelarray[$key]['width'] = 700;
							$modelarray[$key]['height'] = 350;
							$modelarray[$key]['height'] = 350;
							$modelarray[$key]['archive'] = 'management';
							$modelarray[$key]['action'] = 'tab';
							$modelarray[$key]['loadfun'] = 'modelarticlelist';
							if ($key > 6) {
								break;
							}
						}
					}
					$rsList['linked'] = array_merge_recursive($menulink, $modelarray);
				} else {
					$rsList['linked'] = $menulink;
				}
				$menulinkarray[] = $rsList;
				$i++;
			}
			$menu = $this->dbcache->cachesave('menu_' . $type, $menulinkarray);
			$menu = $menu ? $menu : $menulinkarray;
			unset($menulinkarray);
		}

		$this->ectemplates->assign('powerlist', $this->esp_powerlist);
		$this->ectemplates->assign('archive', $archive);
		$this->ectemplates->assign('action', $action);
		$this->ectemplates->assign('loadfun', $loadfun);
		$this->ectemplates->assign('menulinkarray', $menu);
		$output = $this->ectemplates->fetch($filename);
		return $output;
	}

	public function call_tabmenubotton($para, $filename='tabmenubotton') {
		include_once admin_ROOT . adminfile . '/include/inc_formtypelist.php';

		$menutype = empty($para[0]) ? 'loglist' : $para[0];
		$lng = empty($para[1]) ? $this->CON['default_lng'] : $para[1];
		$mid = empty($para[2]) ? 0 : $para[2];
		$isclass = empty($para[3]) ? 0 : $para[3];
		$companyid = empty($para[4]) ? 0 : $para[4];  //[%beark name=tabmenubotton class=$listfunction,$lng,$mid,$isclass,$companyid%]
		$id = empty($para[5]) ? 0 : $para[5];
		
		$today = date('Y-m-d'); 
		$yesterday = date('Y-m-d',strtotime('now')-86400);
		$date = array('today'=>$today,'yesterday'=>$yesterday);
		
		$archive = $this->fun->accept('archive', 'G');
		$action = $this->fun->accept('action', 'G');
		$this->ectemplates->assign('conlist', $this->CON[$menutype]);
		$this->ectemplates->assign('powerlist', $this->esp_powerlist);
		$powerarray = $this->get_power_array();
		$this->ectemplates->assign('powerarray', $powerarray['list']);
		$this->ectemplates->assign('powernum', $powerarray['num']);
		$this->ectemplates->assign('admin_userid',$this->esp_adminuserid);

		$lnglist = $this->get_lng_array();
		$this->ectemplates->assign('lnglist', $lnglist['list']);
		$this->ectemplates->assign('lngnum', $lnglist['num']);

		$memberpuv = $this->get_member_purview_array();
		$this->ectemplates->assign('memberpuvlist', $memberpuv['list']);
		$this->ectemplates->assign('pubnum', $memberpuv['num']);
		
		$membersource = $this->get_member_source_array();
		$this->ectemplates->assign('membersource', $membersource['list']);
		$this->ectemplates->assign('sounum', $membersource['num']);

		$modelarray = $this->get_model(0, $lng, $isclass);
		$this->ectemplates->assign('modelarray', $modelarray['list']);
		$this->ectemplates->assign('modelnum', $modelarray['num']);
		
		$companyarray = $this->get_company_array($companyid,$lng);
		$this->ectemplates->assign('companyarray', $companyarray['list']);
		$this->ectemplates->assign('companynum', $companyarray['num']);
		
		$memarray = $this->get_admember_list($id,$lng);
		$this->ectemplates->assign('memarray', $memarray['list']);
		$this->ectemplates->assign('memnum', $memarray['num']);

		$dclabel = $this->get_doclabel_array(0, $mid, $lng);
		$this->ectemplates->assign('dclabellist', $dclabel['list']);
		$this->ectemplates->assign('dclabelnum', $dclabel['num']);

		$bbslabel = $this->get_bbslabel_array(0, $lng, 1);
		$this->ectemplates->assign('bbslabellist', $bbslabel['list']);
		$this->ectemplates->assign('bbslabelnum', $bbslabel['num']);

		$this->ectemplates->assign('lantype', $LANPACKTYPE);
		$this->ectemplates->assign('lng', $lng);
		$this->ectemplates->assign('mid', $mid);
		$this->ectemplates->assign('isclass', $isclass);
		$this->ectemplates->assign('action', $action);
		$this->ectemplates->assign('menutype', $menutype);
		$this->ectemplates->assign('date', $date);
		$output = $this->ectemplates->fetch($filename);
		return $output;
	}

	public function call_tablabel($para, $filename='tablabel') {

		$menutype = empty($para[0]) ? 'loglist' : $para[0];
		$archive = $this->fun->accept('archive', 'G');
		$action = $this->fun->accept('action', 'G');
		$this->ectemplates->assign('powerlist', $this->esp_powerlist);
		$this->ectemplates->assign('archive', $archive);
		$this->ectemplates->assign('action', $action);
		$this->ectemplates->assign('menutype', $menutype);
		$output = $this->ectemplates->fetch($filename);
		return $output;
	}

}
?>
